public class Solution1223 {
    public int dieSimulator(int n, int[] rollMax) {
        int[][][] f=new int[n+1][6][16];
        int mod=1000000007;
        for (int i=0;i<6;i++) {
            f[1][i][1]=1;
        }
        for (int i=2;i<=n;i++){
            for (int j=0;j<6;j++){
                for (int k=1;k<=rollMax[j];k++){
                    if (k==1){
                        for (int t=0;t<6;t++){
                            if (t!=j){
                                for (int p=1;p<=rollMax[t];p++){
                                    f[i][j][k]=(f[i][j][k]+f[i-1][t][p])%mod;
                                }
                            }
                        }
                    }else {
                        f[i][j][k]=f[i-1][j][k-1];
                    }
                }
            }
        }
        int ans=0;
        for (int i=0;i<6;i++){
            for (int j=1;j<=rollMax[i];j++){
                ans=(ans+f[n][i][j])%mod;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1223().dieSimulator(2,new int[]{1,1,2,2,2,3}));
    }
}
